﻿using System;
using System.Windows.Forms;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

namespace Outlook.WorkItems.Extension.Controls
{
    public class QueryNode : TreeNode
    {
        public QueryDefinition TeamQuery { get; set; }
        public string TeamServerUri
        {
            get
            {
                bool find = false;
                TreeNode tmpNode = Parent;
                while (tmpNode != null && find == false)
                {
                    if (tmpNode is TeamProjectNode)
                        find = true;
                    else
                        tmpNode = tmpNode.Parent;
                }
                if (find && tmpNode != null)
                    return ((TeamProjectNode)tmpNode).TeamServerUrl;
                return null;
            }
        }
        public QueryNode(QueryDefinition teamQuery)
        {
            TeamQuery = teamQuery;
            Text = TeamQuery.Name;
            Name = teamQuery.Name;
            switch (teamQuery.QueryType)
            {
                case QueryType.List:
                    ImageIndex = 6;
                    SelectedImageIndex = 6;
                    break;
                case QueryType.OneHop:
                    ImageIndex = 7;
                    SelectedImageIndex = 7;
                    break;
                case QueryType.Tree:
                    ImageIndex = 8;
                    SelectedImageIndex = 8;
                    break;
                default:
                    break;
            }
        }
    }
}
